package books4africa

import static org.junit.Assert.*
import org.junit.*

class TeacherTests {
        
    void testPersistence(){
        //create a donor and save it in the database
        Teacher test = new Teacher(userID: "test1", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3).save();
        
        
        
        Teacher retrieved = Teacher.findByUserID("test1");
        
        assertEquals(test, retrieved)
        
    }
    
    void testInventoryList(){
        //create an inventoryList to add to the book's inventory lists
        Teacher hasIList = new Teacher(userID: "test1", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3).save()
        
        InventoryList iList = new InventoryList(quantity: 30, donor: new 
            Donor(userID:"hullabaloo@gmail.net", password: "password", 
                listOfCategories: null))
            
        hasIList.addToInventoryLists(iList);
        
        Teacher foundTeacher = Teacher.get(hasIList.id);
        
        assertEquals(foundTeacher.inventoryLists.size(), 1)
       
    }
    
    void testDonationList(){
        //create an inventoryList to add to the book's inventory lists
        Teacher hasDList = new Teacher(userID: "test1", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3).save()
        
        DonationList dList1 = new DonationList(quantity: 30, donor: new 
            Donor(userID:"hullabaloo@gmail.net", password: "password", 
                listOfCategories: null))
        
        DonationList dList2 = new DonationList(quantity: 62, donor: new 
            Donor(userID:"hullabaloo@gmail.net", password: "password", 
                listOfCategories: null))
            
        hasDList.addToDonationLists(dList1);
        hasDList.addToDonationLists(dList2);
        
        Teacher foundTeacher = Teacher.get(hasDList.id);
        
        assertEquals(foundTeacher.donationLists.size(), 2)
    }
    
    void testBookRequest(){
        //create an inventoryList to add to the book's inventory lists
        Teacher hasBRequest = new Teacher(userID: "test1", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3).save()
        
        BookRequest bRequest1 = new BookRequest(requestDescription: "test1", 
                title: "title1", category: "category", gradeLower: 1, 
                gradeHigher: 6, qty: 20, dateMinString: "min", 
                dateMaxString: "max")
        
        BookRequest bRequest2 = new BookRequest(requestDescription: "test2", 
                title: "title2", category: "category", gradeLower: 1, 
                gradeHigher: 6, qty: 20, dateMinString: "min", 
                dateMaxString: "max")
            
        BookRequest bRequest3 = new BookRequest(requestDescription: "test3", 
                title: "title3", category: "category", gradeLower: 1, 
                gradeHigher: 6, qty: 20, dateMinString: "min", 
                dateMaxString: "max")
            
        hasBRequest.addToBookRequests(bRequest1);
        hasBRequest.addToBookRequests(bRequest2);
        hasBRequest.addToBookRequests(bRequest3);
        
        Teacher foundTeacher = Teacher.get(hasBRequest.id);
        
        assertEquals(foundTeacher.bookRequests.size(), 3)
    }
}
